Skip to content

BUG: Choose the scale of each fit in the original data units - #1044

Open
WeiLiuu wants to merge 1 commit into
bashtage:mainfrom
WeiLiuu:fix/rescale-refit-window
Open

WeiLiuu wants to merge 1 commit into
bashtage:mainfrom
WeiLiuu:fix/rescale-refit-window

Conversation

@WeiLiuu

@WeiLiuu WeiLiuu commented Nov 28, 2026

Copy link
Copy Markdown

Fitting a second window with rescale=True can choose the wrong scale. For example, these two fits of the same window return 0.1 and 100.0 on main.

import numpy as np
from arch.univariate import ZeroMean

y = np.tile([-1.0, 1.0], 200) * np.repeat([0.0001, 0.02], 200)
model = ZeroMean(y, rescale=True)
model.fit(last_obs=200, disp="off")
print(model.fit(first_obs=200, disp="off").scale)
print(ZeroMean(y, rescale=True).fit(first_obs=200, disp="off").scale)

The scale check sees residuals in the units of the previous fit, then applies the new multiplier to the original observations. In a seeded GARCH(1,1) example both fits report convergence, but the refit stays at the starting values (alpha 0.2, beta 0.7, against 0.172 and 0.778 for a fresh model), and its one-step variance forecasts differ by up to 31% after converting back to the original units.

Restore the original observations and rebuild the regressors before checking the next window. The regression test refits an ARX(1) on a second window at three amplitudes and checks the scale, parameters and one-step forecasts against OLS on that window. The fast suite passes (31,726 passed, 19 skipped).

AI use: Claude and Codex did most of the work, the patch and the test, and drafted this text.

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.50%. Comparing base (d3e858f) to head (d6c7e71).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1044   +/-   ##
=======================================
  Coverage   99.50%   99.50%           
=======================================
  Files         154      154           
  Lines       34868    34891   +23     
  Branches     2639     2640    +1     
=======================================
+ Hits        34694    34717   +23     
  Misses         98       98           
  Partials       76       76           
Flag Coverage Δ
adder 99.44% <100.00%> (+<0.01%) ⬆️
subtractor 99.44% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant